package com.such.kit.calendar.period.impl;

import java.text.ParseException;
import java.util.Calendar;
import com.such.kit.calendar.DateCalculate;
import com.such.kit.calendar.DatePeriodHelper;
import com.such.kit.calendar.period.DatePeriod;
import com.such.kit.string.StringCommons;

public class YearPeriod extends DatePeriod {

	public DatePeriod add(int amount) throws ParseException {
		return DatePeriodHelper.getInstance(DatePeriodHelper.FREQ_YEAR, 
				super.sfd.format(DateCalculate.add(super.date, amount, DateCalculate.UNIT_YEAR)), super.format);
	}

	public DatePeriod subtract(int amount) throws ParseException {
		return DatePeriodHelper.getInstance(DatePeriodHelper.FREQ_YEAR, 
				super.sfd.format(DateCalculate.subtract(super.date, amount, DateCalculate.UNIT_YEAR)), super.format);
	}

	public String firstFreqDay() {
		String date = StringCommons.merger(super.calendar.get(Calendar.YEAR), "-01-01");
		try {
			date = super.sfd.format(super.baseSfd.parse(date));
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
		return date;
	}

	public String lastFreqDay() {
		String date = StringCommons.merger(super.calendar.get(Calendar.YEAR), "-12-31");
		try {
			date = super.sfd.format(super.baseSfd.parse(date));
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
		return date;
	}

}
